<?php 

class Make_a_payment_model extends Model
{
    function __construct()
    {
        parent::__construct();
        
        $this->load->database();        
    }
    
    function selectAllCountry()
    {       
       
       $this->db->order_by('country_name asc');
       
       $query = $this->db->get('bur_countries');
       
       return $query->result();    
    }
    
    function getBAnkDetails()
    {
        $cond = array('bank_manager_id' => '1');
       $query = $this->db->get_where('bur_bank_managers',$cond);
       
       return $query->result(); 
    }
    
    function insertpayment($arr)
    {
        $query = $this->db->insert('bur_payments', $arr);
        
        return $this->db->insert_id();
        
    }
    
    function deletepaymentfail()
    {
        $arr = array('id' => $this->input->post('orderid'));
        
        $query = $this->db->delete('bur_payments', $arr);
        
        return $query;
    }
    
    function updatepaymentsuccess($arr, $cond)
    {
        $this->db->where($cond);
        
        $query = $this->db->update('bur_payments', $arr);
        
        return $query;
    }
    
    function getAdminEmail()
	{
		$query = $this->db->get('bur_admin_emails');
		$arr = array();
		if($query->num_rows > 0)
		{
			foreach($query->result() as $rows)
			{
				if($rows->email_address != '')
				{
					array_push($arr, $rows->email_address);
				}
			}
		}
		return $arr;
	}
    
    function sendemailBybanktype($id)
    {
        $query_res = $this->db->get_where('bur_payments',array('id' => $id));
        
        $query = $query_res->result();
        
        
        $config = array(
    		'mailtype'=>'html'
        );
        
        foreach($query as $row)
        {
            $name = $row->name;
            $company = $row->companyName;
            $telephone = $row->telephone;
            $email = $row->email;
            $payfor = $row->payfor;
            $country = $row->country;
            $paymentType = $row->paymentType;
            $amount = $row->amount;
        }
        $data = array(                              
            'name'=> $name,
            'company' => $company,
            'telephone' => $telephone,
            'email' => $email,
            'payfor' => $payfor,
            'country' => $country,
            'paymentType' => $paymentType,
            'amount' => $amount
        );        
        
        $email_content = $this->load->view(TEMPLATE_NAME.'/front/mail/make_a_payment',$data, true);
        
        //$email_content_user = $this->load->view(TEMPLATE_NAME.'/front/mail/make_a_payment_user',$data, true);
        
        $this->load->library('email');
        $this->email->initialize($config);
        $this->email->from('noreply@mykprisguide.com', NOREPLY_ADD);
        $this->email->to($this->getAdminEmail());
        
        $this->email->reply_to('noreply@mykprisguide.com', NOREPLY_ADD);
              
        $this->email->subject('A new payment from '.NOREPLY_ADD);
        $this->email->message($email_content);                
        $this->email->send();
        
        /*$this->email->from('noreply@mykprisguide.com', NOREPLY_ADD);
        $this->email->to($email);
        
        $this->email->reply_to('noreply@mykprisguide.com', NOREPLY_ADD);
              
        $this->email->subject('A new payment from '.NOREPLY_ADD);
        $this->email->message($email_content_user);                
        $this->email->send();*/
        
        return true;	
    }
    
}
?>